import { GSprite } from "../../../../com/mui/controls/GSprite";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Language } from "../../../../extend/language/Language";
import { CountryMoneyRecordPanel } from "./CountryMoneyRecordPanel";
import { ResFileConst } from "../../resource/ResFileConst";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { MsgManager } from "../../manager/MsgManager";
import { Cache } from "../../cache/Cache";
import { ECategory } from "../../../../Message/Public/ECategory";
import { EProp } from "../../../../Message/Public/EProp";
import { ItemData } from "../../resource/info/ItemData";
import { ColorConfig } from "../../resource/ColorConfig";
import { FlowerBg } from "../common/FlowerBg";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { ImgBtn } from "../copy/btn/ImgBtn";
type int = number;
//class CountryMoneyPanel
    
    export  class CountryMoneyPanel extends GSprite
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createGImageBitmap(ImagesConst.CountryMoneyBg, 0, 0, this);
            this._flowerBg = ObjCreate.createFlowerBg(0, 310, 522, 115, this);
            ObjCreate.createGImageBitmap(ImagesConst.CountryMoneyBtnBg, 270, 323, this);
            var loc1=new GTextFormat(FontUtil.EmbedNumberName, 22, 15788607);
            this._countryMoneyTxt = ObjCreate.createGTextField("123456", 145, 7, 300, 30, this, loc1);
            this._countryMoneyTxt.embedFonts = true;
            var loc2=GlobalStyle.setTextFormatLeading(GlobalStyle.textFormat1, 5);
            var loc3=Language.getString(36505);
            this._descTxt = ObjCreate.createGTextField("", 30, 263, 475, 60, this, loc2);
            this._descTxt.wordWrap = true;
            this._descTxt.multiline = true;
            this._descTxt.htmlText = loc3;
            this._contributionTxt = ObjCreate.createGTextField("", 20, 330, 300, 20, this, GlobalStyle.textFormat6);
            this._propTip = ObjCreate.createGTextField(Language.getString(36506), 20, 365, 300, 60, this, GlobalStyle.setTextFormatAlign(loc2, "left"));
            this._propTxt = ObjCreate.createGTextField("", this._propTip.x + this._propTip.textWidth, 365, 300, 60, this, loc2);
            var loc4=Language.getString(36507);
            this._btnHelp = ObjCreate.createImgBtn(ImagesConst.RuleExplain, 180, 330, 60, 23, this, "Button");
            this._btnHelp.gbutton.toolTipData = loc4;
            this._moneyDelRecord = new CountryMoneyRecordPanel();
            this._moneyDelRecord.x = 525;
            this._moneyDelRecord.y = -3;
            addChild(this._moneyDelRecord);
            this._moneyAddRecord = new CountryMoneyRecordPanel();
            this._moneyAddRecord.x = 525;
            this._moneyAddRecord.y = 210;
            addChild(this._moneyAddRecord);
            this._giveCountryMoneyBtn = ObjCreate.createGLoadedButton(ResFileConst.IntegralShopBtn, 345, 355, 160, 46, this);
            this._giveCountryMoneyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGiveCountryMoneyBtnClickHandler);
            this._btnLabel = ObjCreate.createBitmap("", 367, 365, this);
            LoaderHelp.addResCallBack(ResFileConst.countryMoney, this.onResLoaded);
            return;
        }

        /* internal  */onResLoaded(): void
        {
            this._moneyDelRecord.titleBmp = ImagesConst.CountryMoneyDelRecord;
            this._moneyAddRecord.titleBmp = ImagesConst.CountryMoneyAddRecord;
            this._btnLabel.bitmapData = GlobalClass.getBitmapData(ImagesConst.CountryMoneyBtnLabel);
            return;
        }

        /* internal  */onGiveCountryMoneyBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=null;
            var loc1=this.getAllCountryProp();
            if (loc1 && loc1.length) 
            {
                loc2 = new Map<any, any> /* flash.utils.Dictionary */();
                loc2 = this.getItemUidMap(this.getAllCountryProp(), loc2);
                Dispatcher.dispatchEvent(new DataEvent(EventName.CountryGiveCountryMoney, loc2));
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(36508));
            }
            return;
        }

        /* internal  */getAllCountryProp(): Array<any>
        {
            var loc5=0;
            var loc1=Cache.instance.pack.backPackCache;
            var loc2=loc1.getTypeItems(ECategory._ECategoryProp, EProp._EPropCountryContrStatic);
            var loc3=loc1.getTypeItems(ECategory._ECategoryProp, EProp._EPropCountryContrDynamic);
            var loc4=[];
            var loc6=loc2.length;
            loc5 = 0;
            while (loc5 < loc6) 
            {
                loc4.push(loc2[loc5]);
                ++loc5;
            }
            loc6 = loc3.length;
            loc5 = 0;
            while (loc5 < loc6) 
            {
                loc4.push(loc3[loc5]);
                ++loc5;
            }
            return loc4;
        }

        /* internal  */getItemUidMap(arg1: Array<any>, arg2: Map<any, any> /* flash.utils.Dictionary */): Map<any, any> /* flash.utils.Dictionary */
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            if (arg1 && arg1.length) 
            {
                loc1 = 0;
                loc2 = 0;
                loc2 = arg1.length;
                loc1 = 0;
                while (loc1 < loc2) 
                {
                    if (loc3 = arg1[loc1]) 
                    {
                        arg2[loc3.uid] = loc3.itemAmount;
                    }
                    ++loc1;
                }
            }
            return arg2;
        }

        public setCountryMoney(arg1: int): void
        {
            this._countryMoneyTxt.htmlText = arg1 + "";
            return;
        }

        public updateContribution(arg1: int): void
        {
            this._contributionTxt.htmlText = Language.getString(36509) + arg1;
            return;
        }

        public updateMoneyRecord(arg1: Array<any>, arg2: Array<any>): void
        {
            this._moneyDelRecord.updateRecord(arg1);
            this._moneyAddRecord.updateRecord(arg2);
            return;
        }

        public updateMyProp(): void
        {
            var loc4=null;
            var loc5=null;
            var loc6=0;
            var loc1=this.getAllCountryProp();
            var loc2="";
            var loc3=loc1.length;
            if (loc3 > 0) 
            {
                if (loc3 > 3) 
                {
                    loc3 = 3;
                }
                loc5 = "";
                loc6 = 0;
                while (loc6 < loc3) 
                {
                    if (loc4 = loc1[loc6] as ItemData) 
                    {
                        loc5 = ColorConfig.instance.getItemColorString(loc4.color);
                        loc2 = loc2 + "<font color=\'" + loc5 + "\'>" + loc4.name + "*" + loc4.itemAmount + "</font>\n";
                    }
                    ++loc6;
                }
            }
            else 
            {
                loc2 = "<font color=\'#ffff00\'>" + Language.getString(36508) + "</font>";
            }
            this._propTxt.htmlText = loc2;
            return;
        }

        /* internal */ /* var */_flowerBg: FlowerBg;

        /* internal */ /* var */_moneyDelRecord: CountryMoneyRecordPanel;

        /* internal */ /* var */_moneyAddRecord: CountryMoneyRecordPanel;

        /* internal */ /* var */_giveCountryMoneyBtn: GLoadedButton;

        /* internal */ /* var */_btnLabel: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_countryMoneyTxt: GTextFiled;

        /* internal */ /* var */_contributionTxt: GTextFiled;

        /* internal */ /* var */_descTxt: GTextFiled;

        /* internal */ /* var */_propTip: GTextFiled;

        /* internal */ /* var */_propTxt: GTextFiled;

        /* internal */ /* var */_btnHelp: ImgBtn;
    }
